package ejemplosAR;

import picking.Picker;
import processing.core.*;
import processing.video.*;
import jp.nyatla.nyar4psg.*;

public class WithPicking extends PApplet{

	private static final long serialVersionUID = 1L;
	private static final String PARA = "/Users/marthagarzon/Desktop/Juan Manuel/Workspace/ModuloSimulacion/data/camera_para.dat";
	private static final String HIRO = "/Users/marthagarzon/Desktop/Juan Manuel/Workspace/ModuloSimulacion/data/patt.hiro";
	
	private Capture cam;
	private MultiMarker nya;
	private int cr,cg,cb;
	@SuppressWarnings("unused")
	private int c=0;
	private Picker picker;

	public void setup() {
		println(MultiMarker.VERSION);
		size(640,480,P3D);
		colorMode(RGB, 100);
		nya=new MultiMarker(this,width,height,PARA,NyAR4PsgConfig.CONFIG_PSG);
		nya.addARMarker(HIRO,80);//id=0
		picker = new Picker(this);
		cam=new Capture(this,640,480);
		cr=cg=cb=100;
	}

	public void draw()
	{
		c++;
		if (cam.available()) {
			cam.read();
			nya.detect(cam);
			hint(DISABLE_DEPTH_TEST);
			image(cam,0,0);
			hint(ENABLE_DEPTH_TEST);
			if(nya.isExistMarker(0)){
				picker.start(0);
				nya.beginTransform(0);
				fill(cr,cg,cb);
				translate(0,0,20);
				box(40);
				nya.endTransform();
			}
		}
	}

	public void mouseClicked() {
		int id = picker.get(mouseX, mouseY);
		if (id ==0) {
			cr=(int) (random(0,100));
			cg=(int) (random(0,100));
			cb=(int) (random(0,100));
		}
	}

}